package top.luhancc.retry;

import com.burukeyou.retry.core.FastRetryBuilder;
import com.burukeyou.retry.core.FastRetryer;
import com.burukeyou.retry.core.RetryResultPolicy;

import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;

/**
 * @author luHan
 * @create 2025/8/28 10:23
 * @since 1.0.0
 */
public class UseFastRetryBuilder {
    public static void main(String[] args) throws ExecutionException, InterruptedException {
        RetryResultPolicy<String> resultPolicy = result -> result.equals("444");
        FastRetryer<String> retryer = FastRetryBuilder.<String>builder()
                .attemptMaxTimes(3)
                .waitRetryTime(3, TimeUnit.SECONDS)
                .retryIfException(true)
                .retryIfExceptionOfType(TimeoutException.class)
                .exceptionRecover(true)
                .resultPolicy(resultPolicy)
                .build();

        CompletableFuture<String> future = retryer.submit(() -> {
            System.out.println("重试");
            //throw new Exception("test");
            //int i = 1/0;
            if (0 < 10) {
                throw new TimeoutException("test");
            }
            return "444";
        });

        String o = future.get();
        System.out.println("结果:" + o);
    }
}
